
public class Crypting {


	public static void main(String[] args) {
		String test = "Test123456";
		String result = crypting(test);
		System.out.println(result);
		
		String decriptedString = decrypt(result);
		System.out.println(decriptedString);
		
		String test2 = decript2(result);
		System.out.println(test2);

		
	}


	static String crypting(String str){
		char[] strArr = str.toCharArray();
		String temp1 = "";
		String temp2 ="";
		if(str.isEmpty() || str == null){
			System.out.println("String is empty!");
		}
		
		for (int i = 0; i < strArr.length; i++) {
			if(i %2 == 0){
				temp1+=strArr[i];
			}
			else {
				temp2+=strArr[i];
			}
		}
		
		return temp1+temp2;
		
		
	}
	
	static String decrypt(String str){
		char[] strAsCharArr = str.toCharArray();
		char[] result = new char[str.length()];
		int i = 0;
		int k = 0;
		
		while(i < result.length){
			result[i] = strAsCharArr[k];
			i+=2;
			k++;
		}
		
		i = 1;
		
		while(i < result.length){
			result[i] = strAsCharArr[k];
			i+=2;
			k++;
		}
	
		return new String(result);
	}
	
	static String decript2(String str){
		String result ="";
		int len = str.length();
		
		
		for (int i = 0; i <= len/2; i++) {
			result += str.charAt(i);
			if((len/2)+i+1 >= str.length()){
				continue;
			}
			result+= str.charAt((len/2)+i+1);
		}
		
		return result;
	}
	

}
